from sklearn.linear_model import LinearRegression
from sklearn.datasets import load_boston
import numpy as np
from python_ai.common.xcommon import sep
import matplotlib.pyplot as plt

boston = load_boston()
x = boston.data
y = boston.target

# ATTENTION: I should scale the data firstly.

model = LinearRegression()
model.fit(x, y)
sep('theta')
theta0 = model.intercept_
theta1n = model.coef_
print(theta0.shape, theta1n.shape)
theta = np.r_[theta0, theta1n]
print(theta)

sep('score')
print(f'score = {model.score(x, y)}')

sep('predict')
h = model.predict(x)
e = h - y
print(e[:5])
plt.scatter(y, y, s=1, label='target')
plt.scatter(y, h, s=1, label='hypothesis')
plt.show()
